package org.JWCB.system.manager;


import org.JWCB.common.core.constants.CacheConstants;
import org.JWCB.common.redis.service.RedisService;
import org.JWCB.system.domain.user.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UserCacheManager {

    @Autowired
    private RedisService redisService;


    /**
     * 更新用户状态同步redis
     */
    public void updateUserStatus(Long userId,Integer status) {
        User user = redisService.getCacheObject(getUserCacheKey(userId), User.class);
        if(user == null) {
            return;
        }
        user.setStatus(status);
        redisService.setCacheObject(getUserCacheKey(userId),user);
    }

    private String getUserCacheKey(Long userId) {
        return CacheConstants.USER_INFO_KEY+userId;
    }
}
